package com.sskj.xgja.verify;

import com.sskj.xgja.BasePresenter;
import com.sskj.xgja.api.ApiObserver;
import com.sskj.base.utils.RxUtils;
import com.sskj.xgja.api.Api;

import java.io.File;

import okhttp3.MediaType;
import okhttp3.MultipartBody;
import okhttp3.RequestBody;


/**
 * @author Hey
 * Create at  2019/03/20
 */
class Verify1Presenter extends BasePresenter<Verify1Activity> {


    public void verify1(String account, String userName, String idCard, String cardType,String bankNumber,String province,String city,String address) {
        Api.getInstance().verify1("openAccount", account, userName, idCard, cardType,bankNumber,province,city,address)
                .compose(RxUtils.transform())
                .subscribe(new ApiObserver<String>(this, true) {
                    @Override
                    public void onSuccess(String data) {
                        mView.submitSuccess();
                    }
                });
    }
    public void verify3(String bankType, String bankNum, String address, File frontImg, File backImg, File card) {
        MultipartBody.Builder builder = new MultipartBody.Builder();
        builder.setType(MultipartBody.FORM);
        builder.addFormDataPart("cardimg1", frontImg.getName(), RequestBody.create(MediaType.parse("image/png"), frontImg))
                .addFormDataPart("cardimg2", backImg.getName(), RequestBody.create(MediaType.parse("image/png"), backImg))
                .addFormDataPart("cardimg3", card.getName(), RequestBody.create(MediaType.parse("image/png"), card))
                .addFormDataPart("cardType", bankType)
                .addFormDataPart("cardAccount", bankNum)
                .addFormDataPart("cardAddress", address);
        Api.getInstance().verify2(builder.build())
                .compose(RxUtils.transform())
                .subscribe(new ApiObserver<String>(this, true) {
                    @Override
                    public void onSuccess(String data) {
                        mView.verify3Success();
                    }
                });

    }

}
